package com.cw.war.ui {
	import net.libra.core.interfaces.IDestroy;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import net.libra.utils.Reflection;
	
	public class CheckBox extends Sprite implements IDestroy{
		
		private var mc : MovieClip;
		
		public function CheckBox(mc:MovieClip) {
			if (mc is String)
			{
				this.mc = Reflection.createDisplayObjectInstance ( mc as String ) as MovieClip;
			}
			else
			{
				this.mc = mc as MovieClip;
			}
			this.mc.gotoAndStop ( 1 );
			this.mc.mouseChildren = false;
			this.mc.x = 0;
			this.mc.y = 0;
			this.addChild ( this.mc );
			this.addEventListener ( MouseEvent.MOUSE_UP , this.__onBtnMouseUp );
		}
		public function destroy():void
		{
			this.removeEventListener ( MouseEvent.MOUSE_UP , this.__onBtnMouseUp );
			this.removeChild ( this.mc );
			this.mc = null;
		}
		public static function createChekBox(mc:MovieClip):CheckBox {
			var parent : DisplayObjectContainer = mc.parent;
			if (parent)
			{
				var depth : int = parent.getChildIndex ( mc );
				var x : int = mc.x,y : int = mc.y;
				var btn : CheckBox = new CheckBox ( mc );
				parent.addChildAt ( btn , depth );
				btn.x = x;
				btn.y = y;
				return btn;
			}
			return null;
		}
		
		private function __onBtnMouseUp ( e : MouseEvent ) : void {
			if(this.mc.currentFrame == 1) {
				this.mc.gotoAndStop(3);
			}
			else {
				this.mc.gotoAndStop(1);
			}
		}
	}
}